<template>
	<view class="container">
		<view v-if="isLogin">
			<image class="headicon" :src="'http://localhost:8090/freshmenapp/'+userInfo.icon"></image>
			<view class="text-area" v-if="isLogin">
				<text class="title">{{userInfo.nickname}}</text>
			</view>
		</view>
		<view v-if="!isLogin">
			<image class="headicon" :src="userInfo.icon"></image>
			<view class="text-area">
				<button type="primary" size="mini" @click="toLogin">点击登录</button>
			</view>
		</view>
		<view style="width: 100%;">
			<view class="entries">
				<view style="width: 90%; height: 1rpx; background-color: #ccc;margin-top: 50rpx;"></view>
				<view class="entry">
					<image src="../../static/UserInfo.png"
						style="height: 25px;width: 30px;margin-top: 15px;margin-left: 20px;"></image>
					<text>个人信息</text>
					<image src="../../static/more.png"
						style="width: 30px; height: 30px; padding: 22rpx;0;0;22rpx; margin-left: 150px;"></image>
				</view>
				<view style="width: 90%; height: 1rpx; background-color: #ccc; "></view>
				<view class="entry">
					<image src="../../static/purchaseorder.png"
						style="height: 25px;width: 30px;margin-top: 15px;margin-left: 20px;"></image>
					<text>订单列表</text>
					<image src="../../static/more.png"
						style="width: 30px; height: 30px; padding: 22rpx;0;0;22rpx;margin-left: 150px;">
					</image>
				</view>
				<view style="width: 90%; height: 1rpx; background-color: #ccc; "></view>
				<view class="entry">
					<image src="../../static/modify-password.png"
						style="height: 25px;width: 30px;margin-top: 15px;margin-left: 20px;"></image>
					<text>修改密码</text>
					<image src="../../static/more.png"
						style="width: 30px; height: 30px; padding: 22rpx;0;0;22rpx; margin-left: 150px;"></image>
				</view>
				<view style="width: 90%; height: 1rpx; background-color: #ccc; "></view>
				<view class="entry">
					<image src="../../static/yijianfankui.png"
						style="height: 25px;width: 30px;margin-top: 12px;margin-left: 20px;"></image>
					<text>意见反馈</text>
					<image src="../../static/more.png"
						style="width: 30px; height: 30px;padding: 22rpx;0;0;22rpx; margin-left: 150px;">
					</image>
				</view>
				<view style="width: 90%; height: 1rpx; background-color: #ccc; margin-bottom: 50rpx;"></view>
			</view>
			<button type="primary" style="margin-top: 10rpx;" :disabled="!isLogin" @click="logout">退出</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo: {
					userid: null,
					icon: '',
					nickname: '',
					username: null
				},
				isLogin: false
			}
		},
		onLoad() {

		},
		onShow() {
			this.getUserInfo();
		},
		methods: {
			logout() {
				uni.setStorageSync('userInfo', null)
				this.getUserInfo()

			},
			toLogin() {
				uni.navigateTo({
					url: './login'
				})
			},
			getUserInfo() {
				let userInfo = uni.getStorageSync('userInfo')
				if (userInfo) {
					this.userInfo = userInfo
					this.isLogin = true
					console.log('用户已登录，读取成功');
				} else {
					this.userInfo.username = null
					this.userInfo.nickname = null
					this.userInfo.icon = '../../static/my_normal.png'
					this.isLogin = false
				}
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 20rpx;
	}

	.headicon {
		height: 200rpx;
		width: 200rpx;
		margin-top: 80rpx;
		margin-left: 133px;
		margin-right: auto;
		margin-bottom: 50rpx;
		border-radius: 50%;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.entries {
		display: flex;
		align-items: center;
		flex-direction: column;
	}

	.entry {
		display: flex;
		/* flex-direction: row; */
		height: 50px;
		width: 100%;
		/* justify-content: space-between; */
	}

	.entry text {
		display: block;
		height: 40px;
		width: 100px;
		margin-top: 30rpx;
		margin-left: 20rpx;
	}

	.touxiang {}

	.touxiang text {
		float: right;
		margin-right: 165px;
		margin-top: 50px;
	}

	button {
		width: 90%;
	}
</style>